package com.example.activitystudy;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.view.View;

public class MainActivity3 extends AppCompatActivity {

    //MainActivity和service连接需要桥梁
    private ServiceConnection connection=new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {

        }

        @Override
        public void onServiceDisconnected(ComponentName name) {

        }
    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);
    }

    //startService对应的stopService============================
    //启动
    public void startService(View view) {

        startService(new Intent(this,MyService.class));
    }

    //停止
    public void stopService(View view) {
        stopService(new Intent(this,MyService.class));
    }





    //bindService对应的unbindService============================

    public void bindService(View view) {
        bindService(new Intent(this,MyService.class),connection, Context.BIND_AUTO_CREATE);
    }

    public void unbindService(View view) {

        unbindService(connection);
    }
}